package com.easyedu.selection.controller;

import com.easyedu.core.entity.po.OpenCourse;
import com.easyedu.core.util.R;
import com.easyedu.selection.entity.dto.request.ReqDropCourse;
import com.easyedu.selection.entity.dto.request.ReqSelectCourse;
import com.easyedu.selection.service.CourseSelectionService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * @author liumengran
 */
@RestController
@RequestMapping("/selection/course")
public class CourseSelectionController {

    private final CourseSelectionService courseSelectionService;

    public CourseSelectionController(CourseSelectionService courseSelectionService) {
        this.courseSelectionService = courseSelectionService;
    }

    /**
     * 功能描述:查询可选课程
     *
     * @param openInstituteId  1 开放课程唯一id
     * @param openDepartmentId 2 开课学院id
     * @param openYear         3 开放年份 open_year
     * @return : com.easyedu.api.util.R
     **/
    @GetMapping("/can-selection")
    public R getCanSelection(@RequestParam Long openInstituteId, @RequestParam Long openDepartmentId,
                             @RequestParam Integer openYear) {
        List<String> canSelection = courseSelectionService.getCanSelection(openInstituteId, openDepartmentId, openYear);
        return R.ok().data(canSelection);
    }

    /**
     * 功能描述:选课
     *
     * @param reqSelectCourse 选课参数(studentNumber 学生序号 ;courseNumber 课程代号)
     * @return : com.easyedu.api.util.R
     **/
    @PostMapping("/selection")
    public R selectCourse(@RequestBody @Valid ReqSelectCourse reqSelectCourse) {
        return courseSelectionService.selectCourse(reqSelectCourse);
    }

    /**
     * 功能描述:退课
     *
     * @param reqDropCourse 退课参数(studentNumber 学生序号 ;courseNumber 课程代号)
     * @return : com.easyedu.api.util.R
     **/
    @PostMapping("/deselection")
    public R deSelectCourse(@RequestBody @Valid ReqDropCourse reqDropCourse) {
        return courseSelectionService.deSelectCourse(reqDropCourse);
    }

    /**
     * 功能描述:查询已选课程
     *
     * @param studentNumber 1 学生序号
     * @return : com.easyedu.api.util.R
     **/
    @GetMapping("/has-selection")
    public R getHasSelection(@RequestParam Long studentNumber) {
        List<OpenCourse> hasSelection = courseSelectionService.getHasSelection(studentNumber);
        return R.ok().data(hasSelection);
    }
}
